import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
const baseUrl = {
  'dev-url': 'https://uat-yunying.oceanchain.net/hanhai',
  'test-url': 'https://uat-yunying.oceanchain.net/hanhai',
  'prod-url': 'https://uat-yunying.oceanchain.net/hanhai'
}

export default defineConfig(({ mode }) => {
  return {
    // vite 相关配置
    base: ['development'].includes(mode) ? "/" : "/",
    server: {
      port: 9000,
      host: true,
      open: true,
      proxy: {
        "/dev-api": {
          target: baseUrl["dev-url"],
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/dev-api/, ""),
        },
        "/test-api": {
          target: baseUrl["test-url"],
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/test-api/, ""),
        },
        "/prod-api": {
          target: baseUrl["prod-url"],
          changeOrigin: true,
        },
      },
    },
    plugins: [
      vue()
    ],
    resolve: {
      alias: {
        "@": resolve(__dirname, "./src"),
      },
    },
    build: {
      sourcemap: false,
    }
  };
});
